import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
export const constantRoutes = [
    {
        path: '/',
        component: () => import('@views/index/index'),
    },
    {
        path: '/forgetpwd',
        component: () => import('@views/login/forget'),
    },
    {
        path: '/login',
        component: () => import('@views/login/index'),
    },
    {
        path: '/register',
        component: () => import('@views/register/index'),
    },
    {
        path: '/agreement',
        component: () => import('@views/agree/index'),
    },
    {
        path: '/treaty',
        component: () => import('@views/agree/treaty'),
    },
    {
        path: '/category',
        component: () => import('@views/category/index'),
    },
    {
        path: '/category/search',
        component: () => import('@views/category/search'),
    },
    {
        path: '/recommend',
        component: () => import('@views/recommend/index'),
    },
    {
        path: '/recommend/:id',
        component: () => import('@views/recommend/detail'),
    },
    {
        path: '/user',
        component: () => import('@views/user/index'),
    },
    {
        path: '/user/address',
        component: () => import('@views/user/address'),
    },
    {
        path: '/user/findPwd',
        component: () => import('@views/user/findPwd'),
    },
    {
        path: '/order',
        component: () => import('@views/order/index'),
    },
    {
        path: '/order/:id',
        component: () => import('@views/order/detail'),
    },
    {
        path: '/exchange',
        component: () => import('@views/exchange/index'),
    },
    {
        path: '/cart',
        component: () => import('@views/cart/index'),
    },
    {
        path: '/goods/:id',
        component: () => import('@views/goods/index'),
    },
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
